package DataAccess;

/** 
 Helper ��ժҪ˵����
*/
public class Helper
{

	public Helper()
	{
		//
		// TODO: �ڴ˴���ӹ��캯���߼�
		//

	}
	/** 
	 �������������ݿ���������еĴ��ִ���������
	 ���罫һ��C#������ַ���ת�ɿ�ֱ������SQL String
	 
	 @param str Ҫת�����ַ���
	 @return ���ַ����е�"'"���Ϊ"''",Ȼ�����ַ���ǰ���"'"
	 <example>
	 Ҫ�ҳ�FIELD2 = It's �ļ�¼
	 string sql = 
		 "SELECT FIELD1      " +   
		 "  FROM TABLE1      " +
		 " WHERE FIELD2 = {0}";
	 sql = string.Format(sql, ToSQLParamStr("It's"));
	 the final sql to execute will be:
	 SELECT FIELD1
	   FROM TABLE1
	  WHERE FIELD2 = 'It''s'' 
	 </example>
	*/
	public static String ToSQLParamStr(String str)
	{
		return "'" + str.replace("'","''").trim() + "'";
	}
	/** 
	 ���ַ����е�"'"����SQL����еı�﷽ʽ
	 ����"''"����"'"
	 
	 @param str Ҫת�����ַ���
	 @return ���ַ����е�"'"���Ϊ"''"
	*/
	public static String QuotedStr(String str)
	{
		return str.replace("'","''").trim();
	}
	/** 
	 ����SQL��ȥ��\t\n\r������ո�
	 
	 @param sql
	 @return 
	*/
	public static String BeautifulSql(String sql)
	{
		sql = sql.replace("\r","").replace("\t"," ").replace("\n"," ");
		while (sql.indexOf("  ") >= 0)
		{
			sql = sql.replace("  "," ");
		}
		sql = sql.replace(", ",",");
		return sql.trim();
	}
}